<template>
  <div class="login-container flx-center">
    <div class="login-box">
      <!-- <SwitchDark class="dark" /> -->
      <div class="login-left">
        <img class="login-left-img" src="../../assets/login_left.png" alt="login" />
      </div>
      <div class="login-form">
        <div class="login-logo">
          <!-- <img class="login-icon" src="@/assets/images/logo.svg" alt="" /> -->
          <h2 class="logo-text">Philo-咖啡店管理系统</h2>
        </div>
        <!-- <LoginForm /> -->
         <div class="login_wrap">
        <div class="form_wrap">
          
  <el-form
    ref="formRef"
    :model="loginData"
    :rules="rules"
    label-width="100px"
    class="demo-ruleForm">
    <p>登录</p>
    <el-form-item label="用户" prop="username" :rules="[{required: true,message: '此项必填',trigger: 'blur'},]">
      <el-input v-model="loginData. username" autocomplete="off"/>
    </el-form-item>
    <el-form-item label="Password" prop="password">
      <el-input v-model= "loginData.password" type="password" autocomplete="off" />
    </el-form-item>
    
    <el-form-item>
      <el-button type="primary" @click="handleLogin">Submit</el-button>
      <el-button @click="resetForm(ruleFormRef)">Reset</el-button>
      <!-- <p>{{num}}</p>  -->
     </el-form-item> 
  </el-form>
        </div>
    </div> 
      </div>
    </div>
  </div>
</template>

<script >
// import LoginForm from "./components/LoginForm.vue";
// import SwitchDark from "@/components/SwitchDark/index.vue";
import { reactive, toRefs } from 'vue'
import { useStore } from "vuex"
import {useRouter} from "vue-router"
export default {
    name:"login",
    setup(){
        const store =useStore()
        const router = useRouter()
        const count=store.state.number.count
        const data=reactive({
            loginData:{
                username:"",
                password:""
            },
            num:count,
            numStatus:store.getters.countStatus
        })
        const handleLogin=()=>{
            data.loginData
            store.commit('setUserInfo', data.loginData);
            localStorage.setItem("loginData",JSON.stringify(data.loginData));
            localStorage.setItem("token","liushuyu");
            router.push({
                path:"/"
            })
        }
        // console.log("修改qian:getters",store.getters["number/countStatus"])
        // const handleLogin=()=>{
        //     // store.commit('number/setCount',100)
        //     store.dispatch('number/setCountPromise',-1).then(res=>{
        //         alert("xiugai ok")
        //     }).catch(err=>{
        //         alert(err)
        //     }

        //     );
        //     console.log(store.state.number.count)
        //      console.log("修改后getters",store.getters["number/countStatus"])
        // }
        return{
            ...toRefs(data),
            handleLogin
        }
    }
}

</script>

<style>
.login_wrap{
    width: 100%;
    height: 100vh;
    /* background: rgb(21, 111, 67); */
    position: absolute;
    
}
.form_wrap{
    top:50%;
    left:50%;
    transform: translate(-50%,-50%);
    background: rgba(255,255,255,0.8);
    padding: 30px 50px;
    padding-top: 20px;
    border-radius: 5px;
    float:right;
    margin-top: 400px;
    height: 200px;
    text-align: center;
}


.login-container {
  height: 100%;
  min-height: 550px;
  background-color: #eeeeee;
  background-image: url("../../assets/login_bg.svg");
  background-size: 100% 100%;
  background-size: cover;
  
  .login-box {
    position: relative;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-around;
    width: 96.5%;
    height: 94%;
    padding: 0 50px;
    background-color: rgb(255 255 255 / 80%);
    border-radius: 10px;
    .dark {
      position: absolute;
      top: 13px;
      right: 18px;
    }
    .login-left {
      width: 800px;
      margin-right: 10px;
      .login-left-img {
        width: 100%;
        height: 100%;
      }
    }
    .login-form {
      width: 420px;
      padding: 50px 40px 45px;
      background-color: var(--el-bg-color);
      border-radius: 10px;
      box-shadow: rgb(0 0 0 / 10%) 0 2px 10px 2px;
      .login-logo {
        display: flex;
        align-items: center;
        justify-content: center;
        margin-bottom: 45px;
        .login-icon {
          width: 60px;
          height: 52px;
        }
        .logo-text {
          padding: 0 0 0 25px;
          margin: 0;
          font-size: 42px;
          font-weight: bold;
          color: #34495e;
          white-space: nowrap;
        }
      }
      .el-form-item {
        margin-bottom: 40px;
      }
      .login-btn {
        display: flex;
        justify-content: space-between;
        width: 100%;
        margin-top: 40px;
        white-space: nowrap;
        
        .el-button {
          width: 185px;
        }
      }
    }
  }
}

@media screen and (max-width: 1250px) {
  .login-left {
    display: none;
  }
}

@media screen and (max-width: 600px) {
  .login-form {
    width: 97% !important;
  }
}


</style>
